﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcBlog.Common.Models;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;


namespace MvcBlog.ViewModels
{
    public class EntryViewModel
    {

        public EntryViewModel()
        {
        }

        public EntryViewModel(Entry e, List<Comment> comments)
        {
            // TODO: Complete member initialization
            this.Entry_ID = e.Entry_ID;
            this.Subject = e.Subject;
            this.Body = e.Body;
            this.CreateDate = e.CreateDate;
            this.User = e.User;
            this.ListOfComments = comments;
        }

        public void ApplyChanges(Entry e)
        {
            e.Subject = this.Subject;
            e.Body = this.Body;
        }

        public int Entry_ID { get; set; }

        [Required(ErrorMessage = "Bitte einen Titel angeben")]
        public string Subject { get; set; }

        [Required(ErrorMessage = "Bitte einen Text angeben")]
        public string Body { get; set; }
        public DateTime CreateDate { get; set; }
        public User User { get; set; }
        public int NumberOfComments
        {
            get { if (ListOfComments != null) { return ListOfComments.Count(); }
                  else                        { return 0;  }
                }
            set { }
        }
        public string NumberOfCommentsLabel
        {
            get
            {
                if (NumberOfComments <= 0 || NumberOfComments > 1) { return "Kommentare"; }
                else { return "Kommentar"; }
            }
        }
        public List<Comment> ListOfComments { get; set; }

        public string newComment { get; set; }

    }
}